home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGASIC
/
BASFILES.LZH
/
BASTOREL.BAS
< prev
next >
Wrap
BASIC Source File
|
1988-09-10
|
1KB
|
37 lines
'$INCLUDE:'QBTOOLS.INC'
'' DECLARE FUNCTION BaseToReal! (Numbase%, Number$)
FUNCTION BaseToReal! (Numbase%, Number$) STATIC
Base10! = 0 'Clear output.
Number$ = RTRIM$(Number$) 'Remove leading spaces
Number$ = LTRIM$(Number$) 'Remove trailing spaves
Number$ = UCASE$(Number$) 'Convert to uppercase
Length% = LEN(Number$) 'Number of characters
'in input string
IF Numbase% < 0 OR Numbase% > 16 THEN 'Check for valid base
BaseToReal = -1
EXIT FUNCTION
END IF
FOR i% = Length% TO 1 STEP -1
Digit% = ASC(MID$(Number$, i%, 1)) - 48 'Numeric
IF Digit% > 9 THEN
Digit% = ASC(MID$(Number$, i%, 1)) - 55 'Alpha
END IF
IF Digit% < 0 OR Digit% > Numbase% - 1 THEN 'Validate number
BaseToReal! = -1
EXIT FUNCTION
END IF
Base10! = Base10! + Digit% * Numbase% ^ (Length% - i%) 'Conversion
NEXT i%
BaseToReal! = Base10! 'Return to Function
END FUNCTION